//
//  InputTextViews.swift
//  Edaixi-iOS
//
//  Created by 刘树华 on 2017/11/30.
//  Copyright © 2017年 刘树华. All rights reserved.
//

import Foundation
import UIKit
class ToolBarTextField:UITextField  {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupToolBar()
        enablesReturnKeyAutomatically = true
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
    }
    
    fileprivate func setupToolBar() {
        
        let toolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44))
        inputAccessoryView = toolBar
        inputAccessoryView?.backgroundColor = UIColor.lightGray
        let btn = UIButton(frame: CGRect(x: toolBar.bounds.size.width-60, y: 0, width: 60, height: toolBar.bounds.size.height))
        btn.setTitle("完成", for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        btn.setTitleColor(UIColor(red: 81.0/255, green: 164.0/255, blue: 222.0/255, alpha: 1.0), for: .normal)
        toolBar.addSubview(btn)
        btn.addTarget(self, action: #selector(downKeyBoard), for: .touchUpInside)
    }
    
    @objc fileprivate func downKeyBoard() {
        self.resignFirstResponder()
    }
    
}
class ToolBarTextView: UITextView {
    
    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        setTooBar()
        enablesReturnKeyAutomatically = true
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    private func setTooBar () {
        let toolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44))
        inputAccessoryView = toolBar
        inputAccessoryView?.backgroundColor = UIColor.lightGray
        let btn = UIButton(frame: CGRect(x: toolBar.bounds.size.width-60, y: 0, width: 60, height: toolBar.bounds.size.height))
        btn.setTitle("完成", for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        btn.setTitleColor(UIColor(red: 81.0/255, green: 164.0/255, blue: 222.0/255, alpha: 1.0), for: .normal)
        toolBar.addSubview(btn)
        btn.addTarget(self, action: #selector(downKeyBoard), for: .touchUpInside)
    }
    @objc private func downKeyBoard() {
        self.resignFirstResponder()
    }
}

